<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport"
          content="width=device-width,  user-scalable=no">

    <title>Barthel指数</title>

    <style>
        /*.table-a table{border:1px solid #000000}*/

        td {
            vertical-align: bottom;
        }

        #table_guage {
            width: 100%;
        }

        #table_guage hr {
            margin: 6.5px auto;
        }

    </style>


</head>

<body>
<form>

    <div style="font-size: 16px;height: 26px;margin-bottom: 26px;border-bottom: 1px solid #d0d0d0;" class="print-div-hr">
        <label class="print-font16">评定内容</label>
    </div>
    <div class="hide">
        <table border="0" cellspacing="0" cellpadding="0">
            <tr>
                <td align="left" width="80px"><label style="font-size: 13px">陪同者</label></td>
                <td align="left"><input type="text" class="form-control" style="width: 200px" id="text_companion"/>
                </td>
            </tr>
        </table>

    </div>

    <!--<div class="view-page hide">-->
    <!--<table border="0" cellspacing="0" cellpadding="0">-->
    <!--<tr>-->
    <!--<td align="left" width="80px"><label style="font-size: 18px">陪同者</label></td>-->
    <!--<td align="left"><label id="span_companion" style="font-weight:normal;font-size: 18px"></label></td>-->
    <!--</tr>-->
    <!--</table>-->
    <!--</div>-->

    <!--<table id="table_total" class="view-page table table-bordered hide" style="margin-top: 20px;font-size: 13px" border="1"-->
    <!--cellspacing="0" cellpadding="0">-->
    <!--<tr>-->
    <!--<td width="40%" align="center"><label>总分</label></td>-->

    <!--<td width="60%" align="center"><span class="span-total-score"></span></td>-->
    <!--</tr>-->
    <!--<tr>-->
    <!--<td width="40%" align="center"><label>ADL能力缺陷程度</label></td>-->

    <!--<td width="60%" align="center"><span class="span-adl-score"></span></td>-->
    <!--</tr>-->
    <!--</table>-->

    <!--<div style="margin-bottom: 30px;font-size: 20px">-->
    <!--<label>评定内容</label>-->
    <!--</div>-->


    <div class="table-a" style="margin-top: 40px">
        <table id="table_guage" border="0" cellspacing="0" cellpadding="0">
        </table>
    </div>
    <div style="font-size: 16px;height: 26px;margin-top:26px;margin-bottom: 26px;border-bottom: 1px solid #d0d0d0;">
        <label class="print-font16">评定结果</label>
    </div>
    <table id="table_total_edit" class="table table-bordered" style="margin-top: 20px;font-size: 13px" border="1"
           cellspacing="0"
           cellpadding="0">
        <tr>

            <td width="40%" align="center"><span>ADL能力缺陷程度</span></td>

            <td width="60%" align="center"><span class="span-adl-score"></span></td>
        </tr>
        <tr>

            <td width="40%" align="center"><span>总分</span></td>


            <td width="60%" align="center"><span class="span-total-score"></span></td>
        </tr>
    </table>


    <div class="edit-page hide" style="margin-top: 20px">
        <div class="col-sm-8 col-sm-offset-4">
            <button class="btn btn-white col-sm-3" type="button" onclick="myReset()">重置</button>
            <button class="btn btn-primary col-sm-3 col-sm-offset-1" onclick="submitGaugeResult()" type="button">提交
            </button>
        </div>
    </div>
</form>
</body>

<script>

    var totalScore = 0;

    var spanTotalScore = $(".span-total-score");
    var spanAdlScore = $(".span-adl-score");

    //    var tableTotalEdit = $("#table_total_edit");
    //    var tableTotal = $("#table_total");

    var editPage = $(".edit-page");
    var viewPage = $(".view-page");

    var textCompanion = $("#text_companion");
    var spanCompanion = $("#span_companion");

    var gauge_groups = [''];

    var gauge_options = [
        ['进食', '洗澡', '修饰', '穿衣', '控制大便', '控制小便', '用厕', '床椅转移', '平地行45米', '上下楼']
    ];

    builderQuestion();

    //    initPage();
    //
    //
    //    function initPage() {
    //
    //        if (editable == true || editable == 'true') {
    //            builderQuestion(true);
    ////            $(".form-group").removeClass('hide');
    ////            tableTotalEdit.removeClass('hide');
    //            editPage.removeClass('hide');
    //        } else {
    //            builderQuestion(false);
    ////            tableTotal.removeClass('hide');
    //            viewPage.removeClass('hide');
    //            mandy_get_gauge_record(gaugeRecordId,prcpItemId, function (data) {
    //                debugAlert(data.result);
    //                var result = eval('(' + data.result + ')');
    //
    //                for (var i = 0; i < gauge_groups.length; i++) {
    //                    for (var j = 0; j < gauge_options[i].length; j++) {
    //                        var questions = result.questions;
    //                        for (var k = 0; k < questions.length; k++) {
    //                            if (questions[k].key.trim() == gauge_options[i][j].trim()) {
    //                                $("input[name='radio_" + i + "_" + j + "']:eq(" + questions[k].value + ")").attr("checked", 'checked');
    //                            }
    //                        }
    //                    }
    //                }
    //
    //                spanCompanion.text(result.companion);
    //
    //                spanTotalScore.text(result.total_score);
    //
    //                if (result.total_score < 20) {
    //                    spanAdlScore.text("极严重功能缺陷");
    //                } else if (result.total_score < 45) {
    //                    spanAdlScore.text("严重功能缺陷");
    //                }
    //                else if (result.total_score < 70) {
    //                    spanAdlScore.text("中度功能缺陷");
    //                }
    //                else if (result.total_score < 95) {
    //                    spanAdlScore.text("轻度功能缺陷");
    //                }
    //                else if (result.total_score < 100) {
    //                    spanAdlScore.text("ADL自理");
    //                }
    //            });
    //        }
    //
    //    }

    function builderQuestion() {

        var radioType2List = '洗澡&修饰&';
        var radioType3List = '进食&穿衣&控制大便&控制小便&用厕&上下楼&';
        var radioType4List = '床椅转移&平地行45米&';

        var index = 1;

        for (var i = 0; i < gauge_groups.length; i++) {
            for (var j = 0; j < gauge_options[i].length; j++) {

                if (j == 0 && gauge_groups[i] != '') {
                    //添加组标题
                    var groupTr =
                        "<tr><td  height='10px' class='group-margin'></td></tr>" +
                        "<tr><td align='left' ><label>" + gauge_groups[i] + "</label></td></tr>";
                    $("#table_guage").append(groupTr);
                }

                var radio;

                if (radioType2List.indexOf(gauge_options[i][j].trim() + '&') != -1) {
                    radio = '<table width="100%"  border="0" cellspacing="0" cellpadding="0">' +
                        '<tr>' +
                        //                    '<td width="5vw" align="left"></td>' +
                        '<td  width="25%" align="left"><input type="radio" value="5" class="question-radio" onchange="changeSelect()" name="radio_' + i + '_' + j + '"/>独立</label></td>' +
                        '<td  width="25%" align="left"><input type="radio" value="0" class="question-radio" onchange="changeSelect()" name="radio_' + i + '_' + j + '"/>部分独立部分帮助</label></td>' +
                        '<td  width="25%" align="left"></td>' +
                        '<td  width="25%" align="left"></td>' +
                        '</tr></table>';
                } else if (radioType3List.indexOf(gauge_options[i][j].trim() + '&') != -1) {
                    radio = '<table width="100%"   border="0" cellspacing="0" cellpadding="0">' +
                        '<tr>' +
                        //                    '<td width="5vw" align="left"></td>' +
                        '<td  width="25%" align="left"><input type="radio" value="10" class="question-radio" onchange="changeSelect()" name="radio_' + i + '_' + j + '"/>独立</label></td>' +
                        '<td  width="25%" align="left"><input type="radio" value="5" class="question-radio" onchange="changeSelect()" name="radio_' + i + '_' + j + '"/>部分独立部分帮助</label></td>' +
                        '<td  width="25%" align="left"><input type="radio" value="0" class="question-radio" onchange="changeSelect()" name="radio_' + i + '_' + j + '"/>需极大帮助</label></td>' +
                        '<td  width="25%" align="left"></td>' +
                        '</tr></table>';
                } else if (radioType4List.indexOf(gauge_options[i][j].trim() + '&') != -1) {
                    radio = '<table width="100%"   border="0" cellspacing="0" cellpadding="0">' +
                        '<tr>' +
                        //                    '<td width="5vw" align="left"></td>' +
                        '<td  width="25%" align="left"><input type="radio" value="15" class="question-radio" onchange="changeSelect()" name="radio_' + i + '_' + j + '"/>独立</label></td>' +
                        '<td  width="25%" align="left"><input type="radio" value="10" class="question-radio" onchange="changeSelect()" name="radio_' + i + '_' + j + '"/>部分独立部分帮助</label></td>' +
                        '<td  width="25%" align="left"><input type="radio" value="5" class="question-radio" onchange="changeSelect()" name="radio_' + i + '_' + j + '"/>需极大帮助</label></td>' +
                        '<td  width="25%" align="left"><input type="radio" value="0" class="question-radio" onchange="changeSelect()" name="radio_' + i + '_' + j + '"/>完全不能独立</label></td>' +
                        '</tr></table>';
                }

                var selectTr = "<tr>" +
                    "<td align='left' style='font-size:13px;margin-left:10px' id='td_" + i + "_" + j + "'>" + (index++) + " ．" + gauge_options[i][j].trim() + "</td>" +
                    "</tr>" +
                    "<tr><td style='padding-left: 5vw' id='td_select_" + i + "_" + j + "' class='print-td'>" +
                    "</td></tr>" + "<tr><td height='6.5px' style='border-bottom:1px dashed #d0d0d0;' class='print-td'></td></tr><tr><td height='6.5px'  class='print-td-margin'></td></tr>";
//                        "<tr><td height='15px'><hr style='height:1px;border:none;border-top:1px dashed #d0d0d0;'/></td></tr>";

                $("#table_guage").append(selectTr);
                $("#td_select_" + i + "_" + j).append(radio);
            }
        }

//        if (editable == false) {
//            $(".question-radio").attr('disabled', 'disabled');
//        }
    }

    function changeSelect() {

        totalScore = 0;

        for (var i = 0; i < gauge_groups.length; i++) {
            for (var j = 0; j < gauge_options[i].length; j++) {
//                var value=$("#select_" + i + "_" + j).val();
                var value = $("input[name='radio_" + i + "_" + j + "']:checked").val();
                if (typeof(value) == "undefined") {
                    value = 0;
                }
                totalScore += parseInt(value);
            }
        }
        spanTotalScore.text(totalScore);

        if (parseInt(totalScore) <= 20) {
            spanAdlScore.text("极严重功能缺陷");
        } else if (parseInt(totalScore) <= 45) {
            spanAdlScore.text("严重功能缺陷");
        }
        else if (parseInt(totalScore) <= 70) {
            spanAdlScore.text("中度功能缺陷");
        }
        else if (parseInt(totalScore) <= 95) {
            spanAdlScore.text("轻度功能缺陷");
        }
        else if (parseInt(totalScore) == 100) {
            spanAdlScore.text("ADL自理");
        }
    }

    //    function submit() {
    //        changeSelect();
    //        var gauge = {};
    //
    //        gauge.total_score = totalScore;
    //
    //        var questions = [];
    //
    //        var index = 0;
    //
    //        for (var i = 0; i < gauge_groups.length; i++) {
    //            for (var j = 0; j < gauge_options[i].length; j++) {
    //                var questionKey = $("#td_" + i + "_" + j).html();
    //                questionKey = questionKey.split("．")[1].trim();
    //
    //                var result = $("input[name='radio_" + i + "_" + j + "']:checked").val();
    //                if (typeof(result) == "undefined") {
    //                    result = 0;
    //                }
    //                var question = {};
    //                question.key = questionKey;
    //                question.value = result;
    //                questions[index++] = question;
    //            }
    //        }
    //
    //        gauge.questions = questions;
    //
    //        gauge.companion=textCompanion.val();
    //
    //        debugAlert(gauge);
    //
    //        mandy_post_gauge_record_result(gaugeRecordId, JSON.stringify(gauge), function (data) {
    //            debugAlert(data);
    //            utils.msgSuccess("提交成功");
    //        });
    //    }


    function setEditable(edit) {
        editPage.removeClass('hide');
        if (edit == true || edit == 'true') {

//            editPage.removeClass('hide');
//            viewPage.addClass('hide');
        } else {
//            mandy_get_gauge_record(gaugeRecordId,prcpItemId, function (data) {
//                debugAlert(data.result);
//                var result = eval('(' + data.result + ')');
//
//                for (var i = 0; i < gauge_groups.length; i++) {
//                    for (var j = 0; j < gauge_options[i].length; j++) {
//                        var questions = result.questions;
//                        for (var k = 0; k < questions.length; k++) {
//                            if (questions[k].key.trim() == gauge_options[i][j].trim()) {
//                                $("input[name='radio_" + i + "_" + j + "']:eq(" + questions[k].value + ")").attr("checked", 'checked');
//                            }
//                        }
//                    }
//                }
//
//                spanCompanion.text(result.companion);
//
//                spanTotalScore.text(result.total_score);
//
//                if (result.total_score < 20) {
//                    spanAdlScore.text("极严重功能缺陷");
//                } else if (result.total_score < 45) {
//                    spanAdlScore.text("严重功能缺陷");
//                }
//                else if (result.total_score < 70) {
//                    spanAdlScore.text("中度功能缺陷");
//                }
//                else if (result.total_score < 95) {
//                    spanAdlScore.text("轻度功能缺陷");
//                }
//                else if (result.total_score < 100) {
//                    spanAdlScore.text("ADL自理");
//                }
//            });
            textCompanion.attr("disabled", true);
//            viewPage.removeClass('hide');
            editPage.addClass('hide');
            $(".question-radio").attr('disabled', 'disabled');
        }

    }

    function setGaugeResult(result) {
        for (var i = 0; i < gauge_groups.length; i++) {
            for (var j = 0; j < gauge_options[i].length; j++) {
                var questions = result.questions;
                for (var k = 0; k < questions.length; k++) {
                    if (questions[k].key.trim() == gauge_options[i][j].trim()) {
                        $("input[name='radio_" + i + "_" + j + "'][value=" + questions[k].value + "]").attr("checked", 'checked');
                    }
                }
            }
        }

        if (result.companion == null || result.companion == '') {
//            spanCompanion.text("无");
        } else {
//            spanCompanion.text(result.companion);
            textCompanion.val(result.companion);
        }

        spanTotalScore.text(result.total_score);

        if (parseInt(result.total_score) <= 20) {
            spanAdlScore.text("极严重功能缺陷");
        } else if (parseInt(result.total_score) <= 45) {
            spanAdlScore.text("严重功能缺陷");
        }
        else if (parseInt(result.total_score) <= 70) {
            spanAdlScore.text("中度功能缺陷");
        }
        else if (parseInt(result.total_score) <= 95) {
            spanAdlScore.text("轻度功能缺陷");
        }
        else if (parseInt(result.total_score) == 100) {
            spanAdlScore.text("ADL自理");
        }
    }

    function getGaugeResult() {
        changeSelect();
        var gauge = {};

        gauge.total_score = totalScore;

        var questions = [];

        var index = 0;

//        if(textCompanion.val().trim()==null||textCompanion.val().trim()==''){
//            utils.msgError("请填写陪同者!");
//            return;
//        }

        for (var i = 0; i < gauge_groups.length; i++) {
            for (var j = 0; j < gauge_options[i].length; j++) {
                var questionKey = $("#td_" + i + "_" + j).html();
                questionKey = questionKey.split("．")[1].trim();

                var result = $("input[name='radio_" + i + "_" + j + "']:checked").val();
                if (typeof(result) == "undefined") {
//                    result = 0;
                    var noCheckedIndex = i * gauge_groups.length + j + 1;
                    utils.msgError("第" + (index + 1) + "个选项还未评估!");
                    $("input[name='radio_" + i + "_" + j + "']").focus();
                    return;
                }
                var question = {};
                question.key = questionKey;
                question.value = result;
                questions[index++] = question;
            }
        }

        gauge.questions = questions;

        gauge.companion = textCompanion.val().trim();
//        spanCompanion.text(gauge.companion);
        textCompanion.val(gauge.companion);
        debugAlert(gauge);
        return gauge;
    }

    function getCount() {
        spanAdlScore.text(null);
        spanTotalScore.text(null);
    }


</script>

</html>
